returns the coordinate of the centroid given a grid_integer
mask,
in the same coordinate reference system of grid_integer
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(grid_integer), | intent(in) | :: | grid |
input grid |
||
type(Coordinate), | intent(out) | :: | ccoord |
coordinate of computed centroid |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=short), | public | :: | ci |
coordinate |
|||
integer(kind=short), | public | :: | cj |
coordinate |
|||
integer(kind=short), | public | :: | countcell | ||||
integer(kind=short), | public | :: | i | ||||
integer(kind=short), | public | :: | j |
SUBROUTINE CentroidGridInteger & ! (grid, ccoord) IMPLICIT NONE !Arguments with intent in: TYPE (grid_integer), INTENT (IN) :: grid !!input grid !Arguments with intent out or inout TYPE (Coordinate), INTENT (OUT) :: ccoord !! coordinate of computed centroid !local declarations: INTEGER (KIND = short) :: cj, ci !!coordinate INTEGER (KIND = short) :: i, j INTEGER (KIND = short) :: countcell !--------------------------------end of declaration---------------------------- !set coordinate reference system of centroid ccoord % system = grid % grid_mapping cj = 0 ci = 0 countcell = 0 DO i = 1, grid % idim DO j = 1, grid % jdim IF (grid % mat (i,j) /= grid % nodata) THEN countcell = countcell + 1 cj = cj + j ci = ci + i END IF END DO END DO IF ( countcell > 0) THEN cj = cj / countcell ci = ci / countcell ELSE CALL Catch ('error', 'Morphology', 'area zero found while computing centroid coordinates') END IF CALL GetXY (ci, cj, grid, ccoord % easting, ccoord % northing ) RETURN END SUBROUTINE CentroidGridInteger